﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using FRL.DebtChased.Repository;
using FRL.DebtChased.Website;
using FRLUser = FRL.DebtChased.Repository.User;

namespace WebApplication.Finance
{

	/// <summary>
	/// Declaration of AccountAssignment
	/// </summary>
	public partial class AccountAssignment : System.Web.UI.Page
	{

		/////////////////////////////////////////////////////////////
		// Attributes

		/////////////////////////////////////////////////////////////
		// Event handlers

		protected void Page_Load(object sender, EventArgs e)
		{

			// If this is a postback...
			if (this.IsPostBack)
			{

			}
			else
			{

				// TODO
				// This function has changed.


				/*
				// Open the entities
				m_ent = new DebtChasedEntities();

				// Load users for accounts filter
				IDictionary<string, string> userDict = FRLUser.LoadUserDictionary(
					m_ent,
					FRLUser.eUserLoadFlags.FullNameAndManagerSuffix,
					FRLUser.eRoles.FIN_USER |
					FRLUser.eRoles.FIN_USERADMIN |
					FRLUser.eRoles.FIN_MNGADMIN |
					FRLUser.eRoles.FIN_SUPERUSER
				);
				cboAccountFilter.BindToDictionary(userDict);
				cboAccountFilter.Items.Insert(0, new ListItem("[Unassigned Accounts]","0") );
				cboAccountFilter.SelectedIndex = 0;

				// Load the unassigned accounts
				cboAccountFilter_SelectedIndexChanged(null, null);

				// Load users for target managers
				userDict = rep.LoadUserDictionary( 
					SqlDataRepository.eUserLoadFlags.FullNameAndManagerSuffix,					
					DebtChaseWebsite.Entities.User.eRoles.FIN_USERADMIN |
					DebtChaseWebsite.Entities.User.eRoles.FIN_MNGADMIN |
					DebtChaseWebsite.Entities.User.eRoles.FIN_SUPERUSER
				);
				cboTargetManager.DataSource = userDict;
				cboTargetManager.DataTextField = "Value";
				cboTargetManager.DataValueField = "Key";
				cboTargetManager.DataBind();
				cboTargetManager.SelectedIndex = 0;

				// Load the managers users
				cboTargetManager_SelectedIndexChanged(null, null);
				 */

			}

		}

		protected void cboAccountFilter_SelectedIndexChanged(object sender, EventArgs e)
		{

			/*
			// Get the selected account filter
			List<ThinAccountModel> accList = null;
			int iAccountFilter = int.Parse(cboAccountFilter.SelectedValue);
			if (iAccountFilter == 0)
			{

				// Load the unassigned accounts
				accList = _getRep().LoadUnassignedAccounts();

			}
			else
			{

				// Load the accounts for selected user
				accList = _getRep().LoadAccountsForUser(iAccountFilter);

			}

			// Bind to the account grid
			gridAvailableAccounts.DataSource = accList;
			gridAvailableAccounts.DataBind();
			 */

		}

		protected void cboTargetManager_SelectedIndexChanged(object sender, EventArgs e)
		{

			/*
			// Get the selected manager id
			int iManagerId = int.Parse(cboTargetManager.SelectedValue);
			if (iManagerId != 0)
			{

				// Load the users for the selected manager
				IDictionary<string, string> userDict = _getRep().LoadUserDictionary(
					SqlDataRepository.eUserLoadFlags.FullNameAndManagerSuffix, 
					DebtChaseWebsite.Entities.User.eRoles.NotSet,
					iManagerId
				);
				cboTargetCollector.DataSource = userDict;
				cboTargetCollector.DataTextField = "Value";
				cboTargetCollector.DataValueField = "Key";
				cboTargetCollector.DataBind();
				cboTargetCollector.Items.Insert(0, new ListItem("[all collectors]", "0"));

				// Select the top item
				cboTargetCollector.SelectedIndex = 0;

			}
			 */

		}

		protected void cboTargetCollector_SelectedIndexChanged(object sender, EventArgs e)
		{

			/*
			// Get the collector id
			int iCollectorId = int.Parse(cboTargetCollector.SelectedValue);
			if (iCollectorId != 0)
			{

				// Get the accounts for the user
				List<ThinAccountModel> accList = null;
				accList = _getRep().LoadAccountsForUser(iCollectorId);

				// Bind to the account grid
				gridWorkload.DataSource = accList;
				gridWorkload.DataBind();

			}
			 */

		}

	}

}